<?php
	$paymentMode = array('' => 'Select Payment Mode...', 'Cash' => 'Cash', 'Cheque' => 'Cheque', 'Credit Card' => 'Credit Card');
	$relationMode = array('' => 'Select Relationship to Applicant...', 'Father of' => 'Father', 'Mother of' => 'Mother', 'Guardian of' => 'Guardian');
	$creditcardname = array('' => 'Select Credit Card Name', 'Visa' => 'Visa', 'Master' => 'Master', 'Amex' => 'Amex', 'Debit' => 'Debit');
	if($payee != FALSE){
		$firstname = set_value('firstname',$payee->firstname);
		$middlename = set_value('middlename',$payee->middlename);
		$lastname = set_value('lastname',$payee->lastname);
		$name_ext = set_value('name_ext',$payee->name_ext);
		$relation = set_value('relation',$payee->relation);
	}else{
		$firstname = set_value('firstname','');
		$middlename = set_value('middlename','');
		$lastname = set_value('lastname','');
		$name_ext = set_value('name_ext','');
		$relation = set_value('relation','');
	}
	//var_dump($payee);
?>

<style>
	input#amount_money
	{
		padding:10px 20px;
		font-size:30px;
		font-family:DigitaldreamFatNarrowRegular;
		text-align:right;
	}
	span#amount_money_span
	{
		position:absolute;
		font-size:30px;
		margin-top:12px;
		margin-left:12px;
	}
</style>

<div class="row">
	<div class="panel callout"><h6>Add Student Payment Record</h6></div>
	<?$this->load->view('layouts/student_profile_head');?>
	
	<div class="row">
	<div class="large-6 columns">
	<table style="width:100%;">
		<tbody class="table table-bordered table-hover table-striped">
			<tr>
					<td colspan="2" style="text-align:center;">Account Summary.</td>
			</tr>
			<tr>
				<td>Total Payables:</td>
				<td>
					<span style="font-size:20px;" >&#8369;&nbsp;</span>
					<span style="color:#000;font-size:20px;font-weight:bold;"><?=money(round(floatval($total_tuit + $total_matr + $other_total + $misc_total),2));?></span>
				</td>
			</tr>
			<tr>
				<td>Total Paid:</td>
				<td>
					<span style="font-size:20px;" >&#8369;&nbsp;</span>
					<span style="color:#000;font-size:20px;font-weight:bold;"><?=money(round(floatval($amount_due->amount_paid),2));?></span>
				</td>
			</tr>
			<tr>
				<td>Current balance:</td>
				<td>
					<span style="font-size:20px;" >&#8369;&nbsp;</span>
					<span style="color:#AB4705;font-size:20px;font-weight:bold;"><?=money(round(floatval(($total_tuit + $total_matr + $other_total + $misc_total)- $amount_due->amount_paid),2));?></span>
				</td>
			</tr>
		</tbody>
	</table>
	</div>
	<div class="large-6 columns">
	<table class="table table-bordered table-hover table-striped">
		<?if($payment_modes):?>
			<tbody>
				<tr>
					<td colspan="2" style="text-align:center;">Payment Plan Applied</td>
				</tr>
				<tr>
					<td>Payment Plan Name</td>
					<td style="color:#AB4705;font-weight:bold;text-transform:capitalize;"><?php echo $payment_modes->payment_mode; ?></td>
				</tr>
				<!--
				<tr>
					<td colspan="2" style="text-align:center;">Payment Plan Schedule</td>
				</tr>
				<?if($student_payment_schedule):?>
				<tr>
					<td>Month</td>
					<td style="text-align:center;">Amount</td>
				</tr>
				<?foreach($student_payment_schedule as $v):?>
						<?
						if($v->sps_month=='Registration'){
						?>
						<tr>
							<td><?=$v->sps_month;?></td>
							<td  style="text-align:right;"><?=number_format(($v->sps_tuition+$v->sps_matri)+($misc_total+$other_total),2,'.',',');?></td>
						</tr>
						<?php
						}else{
						?>
						<tr>
							<td><?=$v->sps_month;?></td>
							<td  style="text-align:right;"><?=number_format($v->sps_tuition+$v->sps_matri,2,'.',',');?></td>
						</tr>
						<?php
						}
						?>
				<?endforeach;?>
				<?endif;?>
				<!--
				<tr>
					<td>Payment Plan Value</td>
					<td><span style="font-size:20px;" >&#8369;&nbsp;</span><span style="color:#AB4705;font-weight:bold;"><?php echo money(round(floatval($payment_modes->payment_mode_value),2)); ?></span></td>
				</tr>
				-->
				<!--
				<tr>
					<td>Month</td>
					<td style="text-align:right;">Payment Due</td>
					<td style="text-align:right;">Paid</td>
				</tr>
				<?foreach($payment_modes as $v):?>
				<?
					$sum['due'][] = $v->spm_value;
					$sum['paid'][] = $v->student_paid;
				?>
				<tr>
					<td><?=$v->month_name;?></td>
					<td  style="text-align:right;"><?=number_format($v->spm_value,2,'.',',');?></td>
					<?if($v->student_paid == 0.00):?>
					<td style="color:#f00;font-weight:bold;text-align:right;"><?=number_format($v->student_paid,2,'.',',');?></td>
					<?else:?>
					<td  style="color:#035F11;font-weight:bold;text-align:right;"><?=number_format($v->student_paid,2,'.',',');?></td>
					<?endif;?>
				</tr>
				<?endforeach;?>
				<tr class="info">
					<td></td>
					<td style="color:#1212FC;font-weight:bold;text-align:right;"><?=number_format(array_sum($sum['due']),2,'.',',');?></td>
					<td style="color:#1212FC;font-weight:bold;text-align:right;"><?=number_format(array_sum($sum['paid']),2,'.',',');?></td>
				</tr>
				<?if($others):?>
				<tr>
					<td colspan="3" style="font-weight:bold;">Additional Fees</td>
				</tr>
				<?foreach($others as $k => $v):?>
					<?if($type == 'spb'):?>
						<tr>
							<td><?=$v->spb_fee_name;?></td>
							<td style="text-align:right;"><?=$v->spb_remaining_balance;?></td>
							<td style="text-align:right;"><?=$v->spb_amount_paid;?></td>
						</tr>
					<?else:?>
						<tr>
							<td style="text-align:right;"><?=$v->sef_fee_name;?></td>
							<td style="text-align:right;"><?=$v->sef_fee_rate;?></td>
							<td style="text-align:right;">0.00</td>
						</tr>
					<?endif?>
				<?endforeach;?>
					<tr class="info">
						<td style="text-align:right;"></td>
						<td style="text-align:right;"><?=number_format($electives_total,2,'.',',');?></td>
						<td style="text-align:right;"></td>
					</tr>
					<tr class="info">
						<td>Total</td>
						<td style="text-align:right;color:#000;font-size:15px;font-weight:bold;"><?=number_format($amount_due->amount_due + $electives_total,2,'.',',');?></td>
						<td></td>
					</tr>
				<?endif;?>
				-->
			</tbody>
		<?else:?>
			<hr class="clearfix">
			<div class="alert-box">No Payment Plan.</div>
		<?endif;?>
	</table>
	</div>
	</div>
	<div>
	<label class="label">Payment Record Form</label>
	<hr class="clearfix">
	<?if(isset($system_message))echo $system_message;?>
	<? echo validation_errors();?>
	<?echo form_open('fees/add_payment_record','class="custom"');?>
	
	<div class="row collapse">
		<span style="font-size:10px; color:red; display:none;" id="firstname_notice">Payee's Name cannot be blank or must be complete. Required entry.</span>
		<div class="small-4 large-4 columns">
			<span class="prefix">Payee</span>
		</div>
		<div class="small-3 large-3 columns">
			<input type="text" id="firstname" name="firstname" autocomplete="off" placeholder="First Name" value="<?php echo ucwords(strtolower($firstname)); ?>" class="postfix">
		</div>
		<div class="small-2 large-2 columns">
			<input type="text" id="middlename" name="middlename" autocomplete="off" placeholder="Middle Name" value="<?php echo ucwords(strtolower($middlename)); ?>" class="postfix">
		</div>
		<div class="small-2 large-2 columns">
			<input type="text" id="lastname" name="lastname" autocomplete="off" placeholder="Last Name" value="<?php echo ucwords(strtolower($lastname)); ?>" class="postfix">
		</div>
		<div class="small-1 large-1 columns">
			<input type="text" id="name_ext" name="name_ext" autocomplete="off" placeholder="Jr, II etc" value="<?php echo $name_ext=='jr' || $name_ext == 'sr' ? ucwords(strtolower($name_ext)):strtoupper($name_ext); ?>" class="postfix">
		</div>
	</div>

	<div class="row collapse">
		<span style="font-size:10px; color:red; display:none;" id="relation_notice">Choice a Relation. Required entry.</span>
		<div class="small-4 large-4 columns">
			<span class="prefix">Relationship to Applicant</span>
		</div>
		<div class="small-8 large-8 columns">
			<?php echo form_dropdown('relation', $relationMode, $relation, 'id="relation"');?>
		</div>
	</div>

	<div class="row collapse">
		<div class="small-4 large-4 columns">
			<span class="prefix">Cheque No.</span>
		</div>
		<div class="small-8 large-8 columns">
			<input type="text" id="cheque_no" name="cheque_no" autocomplete="off" placeholder="Cheque Number">
		</div>
	</div>

	<div class="row collapse">
		<div class="small-4 large-4 columns">
			<span class="prefix">Credit Card No.</span>
		</div>
		<div class="small-8 large-8 columns">
			<input type="text" id="credit_card_no" name="credit_card_no" autocomplete="off" placeholder="Credit Card Number">
		</div>
	</div>

	<div class="row collapse">
		<div class="small-4 large-4 columns">
			<span class="prefix">Credit Card Name</span>
		</div>
		<div class="small-8 large-8 columns">
			<?php echo form_dropdown('credit_card_name', $creditcardname, set_value('credit_card_name'));?>
		</div>
	</div>

	<div class="row">
		<div class="large-6 columns">
			<label>Amount</label>
			<span id="amount_money_span">&#8369;</span><input id="amount_money" type="text" name="ammount_paid"  placeholder="Amount" value="<?php echo set_value('ammount_paid');?>" required>
		</div>
		<div class="large-6 columns">
			<label>OR Number</label>
			<input type="text" name="spr_or_no" id="spr_or_no" placeholder="O.R Number" value="<?php echo set_value('spr_or_no');?>" required>
		</div>
	</div>
	
	<div class="row">
		<div class="large-6 columns">
			<label>Date Of Payment</label>
			<input type="text" name="date_of_payment"  placeholder="Date: mm/dd/yyyy" class ="datepicker-payment" value="<?php echo set_value('date_of_payment',$current_time);?>" required>
		</div>
		<div class="large-6 columns">
			<label>For The Month Of:</label>
			<?=form_dropdown('month',$months);?>
		</div>
	</div>
	
	<div class="row">
		<div class="large-6 columns">
			<label>Remarks</label>
			<textarea name="remarks"><?php echo set_value('remarks');?></textarea>
		</div>
		<div class="large-6 columns">
			<label>Type of Payment</label>
			<?=form_dropdown('payment_type',array(''=>'-- choose type --','cash'=>'Cash','check/cheque'=>'Check/Cheque','other settlement'=>'Other Settlement'),set_value('payment_type'),'id="payment_mode"');?>
		</div>
	</div>
	<input type="hidden" name="enrollment_id" value="<?echo $enrollment_id;?>">
	<input type="hidden" name="authlink" value="<?echo $authlink;?>">
	<input type="submit" class="button tiny" id="update_fee" name="add_payment_record" value="Add Payment Record">
	</form>
	</div>
</div>

<script>
$('#update_fee').bind('click submit', function(event){
	if($('#spr_or_no').val()!='' && $('#spr_or_no').val()!=' '){
		$("#spr_or_no_notice").css({ display: "none" });
	}else{
		$("#spr_or_no_notice").css({ display: "block" });
	}

	if($('#payment_mode').val()!=''){
		$("#spr_payment_mode_notice").css({ display: "none" });
	}else{
		$("#spr_payment_mode_notice").css({ display: "block" });
	}

	if($('#firstname').val()!=''){
		$("#firstname_notice").css({ display: "none" });
	}else{
		$("#firstname_notice").css({ display: "block" });
	}

	if($('#lastname').val()!=''){
		$("#firstname_notice").css({ display: "none" });
	}else{
		$("#firstname_notice").css({ display: "block" });
	}

	if($('#relation').val()!=''){
		$("#relation_notice").css({ display: "none" });
	}else{
		$("#relation_notice").css({ display: "block" });
	}
  
	if($('#spr_or_no').val()=='' || $('#spr_or_no').val()==' ' || $('#payment_mode').val()=='' || $('#firstname').val()==' ' || $('#firstname').val()==''|| $('#lastname').val()==' ' || $('#lastname').val()==''|| $('#relation').val()==''){
		event.preventDefault();
	}
});
</script>